package com.demo.fulllink.module.vo;

import java.io.Serializable;

public class ResponseVO implements Serializable {
    
    /**
     * 响应状态
     */
    public enum ResponseState {
        SUCCESS, ERROR, UNKNOWN
    }
    
    public ResponseVO() {
        
    }
    
    public static ResponseVO success(Object data) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setState(ResponseState.SUCCESS);
        responseVO.setData(data);
        return responseVO;
    }
    
    public static ResponseVO success(Object data, String message) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setState(ResponseState.SUCCESS);
        responseVO.setMessage(message);
        responseVO.setData(data);
        return responseVO;
    }
    
    public static ResponseVO error(int errorCode, String errorMsg) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setState(ResponseState.SUCCESS);
        responseVO.setErrorCode(errorCode);
        responseVO.setErrorMsg(errorMsg);
        return responseVO;
    }
    
    public static ResponseVO unknown(int errorCode, String errorMsg) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setState(ResponseState.UNKNOWN);
        responseVO.setErrorCode(errorCode);
        responseVO.setErrorMsg(errorMsg);
        return responseVO;
    }
    
    private ResponseState state;
    
    private int errorCode;
    
    private String errorMsg;
    
    private String message;
    
    private Object data;
    
    public ResponseState getState() {
        return state;
    }
    
    public void setState(ResponseState state) {
        this.state = state;
    }
    
    public int getErrorCode() {
        return errorCode;
    }
    
    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }
    
    public String getErrorMsg() {
        return errorMsg;
    }
    
    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }
    
    public Object getData() {
        return data;
    }
    
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
    public void setData(Object data) {
        this.data = data;
    }
    
    public boolean isSuccess() {
        return getState() == ResponseState.SUCCESS;
    }
}
